use std::fs;
use serde_yaml;

#[derive(Debug, serde::Deserialize)]
struct TestConfig {
    app: AppConfig,
    database: DatabaseConfig,
    auth: AuthConfig,
}

#[derive(Debug, serde::Deserialize)]
struct AppConfig {
    port: u16,
    host: String,
}

#[derive(Debug, serde::Deserialize)]
struct DatabaseConfig {
    url: String,
}

#[derive(Debug, serde::Deserialize)]
struct AuthConfig {
    secret_key: String,
}

fn main() {
    // 读取配置文件
    let config_content = fs::read_to_string("config/config.yaml").expect("无法读取配置文件");
    
    // 解析YAML配置
    match serde_yaml::from_str::<TestConfig>(&config_content) {
        Ok(config) => {
            println!("✅ 配置文件解析成功！");
            println!("应用配置: {:?}", config.app);
            println!("数据库配置: {:?}", config.database);
            println!("认证配置: {:?}", config.auth);
        }
        Err(e) => {
            println!("❌ 配置文件解析失败: {}", e);
        }
    }
}